revision:
The property returns the last child element of the specified element. The property is read-only.
Syntax:
element.lastElementChild : the last child element of an element; "null" if no child element exists.
property value:
none :
example
The HTML content of the list's last child is:
The tag name of the last child element is :
<div>
<ul id="myList">
<li>Coffee</li>
<li>Tea</li>
</ul>
<p>The HTML content of the list's last child is: <span id="prop"></span></p>
<p>The tag name of the last child element is : <span id="prop1"></span></p>
</div>
<script>
let text = document.getElementById("myList").lastElementChild.innerHTML;
document.getElementById("prop").innerHTML = text;
let name = document.getElementById("myList").lastElementChild.tagName;
document.getElementById("prop1").innerHTML = name;
</script>
The text of the last child of the select element is:
<div>
<select id="mySelect" size="5" title="choose">
<option>Audi</option>
<option>BMW</option>
<option>Saab</option>
<option>Volvo</option>
</select>
<br><br>
<p>The text of the last child of the select element is:</p>
<p id="prop2"></p>
</div>
<script>
const element = document.getElementById("mySelect");
document.getElementById("prop2").innerHTML = element.lastElementChild.text;
</script>